/*
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2023/10/25 14:30
@File     : errors.go
@Project  : GoProject
@Desc     :
*/
package response

import "github.com/pkg/errors"

var (
	// common errors
	ErrSuccess             = newError(0, "success")
	ErrBadRequest          = newError(400, "Bad Request")
	ErrUnauthorized        = newError(401, "Unauthorized")
	ErrNotFound            = newError(404, "Not Found")
	ErrInternalServerError = newError(500, "Internal Server Error")

	// more biz errors
	ErrUsernameAlreadyUse = newError(1001, "The username is already in use.")
)
var errorCodeMap = map[error]int{}

type Error struct {
	Code int
	Msg  string
}

func (e Error) Error() string {
	return e.Msg
}

func newError(code int, msg string) error {
	err := errors.New(msg)
	errorCodeMap[err] = code
	return err
}
